package io.jt808.proto.req;

import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 终端升级结果通知
 */
@Proto("0108")
@Data
public class JT0108 implements IProto {

    /**
     * 更新类型
     */

    private byte updateType;
    /**
     * 更新结果
     */
    private byte updateResult;

    public final byte[] writeToBytes() {
        AutoBuffer buff = new AutoBuffer();
        buff.writeByte(updateType);
        buff.writeByte(updateResult);
        return buff.array();
    }

    public final void readFromBuf(AutoBuffer buff) {
        updateType = buff.readByte();
        updateResult = buff.readByte();
    }

    public String getUpdateType() {
        switch (updateType) {
            case 0:
                return "terminal";
            case 12:
                return "ICCardScanner";
            default://52
                return "BeiDou";
        }
    }

    public String getUpdateResult() {
        switch (updateResult) {
            case 0:
                return "fail";
            case 1:
                return "success";
            default://2
                return "canceled";
        }
    }


//    public static void main(String[] args) {
//        byte[] bytes = new byte[]{
//                0x44,0x02
//        };
//        AutoBuffer buffer = new AutoBuffer(bytes);
//        JT0108 jt0107 = new JT0108();
//        jt0107.readFromBuf(buffer);
//        System.out.println(jt0107.getUpdateResult());
//        System.out.println(jt0107.getUpdateType());
//    }
}